<template>
  <div class="search-tab-box">
    <div class="search-bar">
      <input
        v-model="keyword"
        placeholder="请输入关键词进行查询"
        @input="inputChange"
        @focus="$emit('focus')"
        @clear="reset_();"
      />
    </div>

    <div v-if="showTab" class="tab-box" @click="activeChange">
      <div id="vehicle-tab-1" :class="{'active': activeIndex === 1}">全部({{ allCount }})</div>
      <div id="vehicle-tab-2" :class="{'active': activeIndex === 2}">在线({{ onlineCount }})</div>
      <div id="vehicle-tab-3" :class="{'active': activeIndex === 3}">离线({{ offlineCount }})</div>
      <div class="line" />
    </div>
  </div>

</template>

<script>/**
   * 组件说明:
   * 创建者: Q
   * 创建时间: 2021/8/18  17:10
   *
   */
export default {
  name: 'VTreeCustomSearch',
  props: {
    search: {
      type: Function,
      required: true
    },
    reset: {
      type: Function,
      required: true
    },
    onlineCount: {
      type: Number,
      default: 0
    },
    offlineCount: {
      type: Number,
      default: 0
    },
    allCount: {
      type: Number,
      default: 0
    },
    showTab: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      keyword: undefined,
      activeIndex: 1
    }
  },
  methods: {
    inputChange() {
      this.search(this.keyword)
    },
    activeChange(e) {
      switch (e.target.id) {
        case 'vehicle-tab-1':
          this.activeIndex = 1
          break
        case 'vehicle-tab-2':
          this.activeIndex = 2
          break
        case 'vehicle-tab-3':
          this.activeIndex = 3
          break
        default:
          this.activeIndex = 1
      }
      this.reset_(false)
      this.$emit('tabChange', this.activeIndex)
    },
    reset_(init = true) {
      this.keyword = ''
      this.reset(init)
    }
  }
}
</script>

<style lang="scss" scoped>
  $text-color2: #aaaaaa;
  $background-color3: #cccccc;
  $main-blue: blue;
  .search-tab-box {
    .search-bar {
      padding: 6px 16px;
      display: flex;
      align-items: center;
    }

    .tab-box {
      display: flex;
      position: relative;
      font-size: 12px;
      font-weight: 400;
      color: $text-color2;
      line-height: 24px;
      text-align: center;
      margin-top: 18px;
      padding-bottom: 4px;
      cursor: pointer;
      > div {
        flex: 1;
        position: relative;
      }
      .active {
        color: $main-blue;
        &:before {
          content: ' ';
          position: absolute;
          bottom: -4px;
          height: 2px;
          left: 0;
          right: 0;
          background-color: $main-blue;
          z-index: 9;
        }
      }
      .line {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 2px;
        background-color: $background-color3;
      }
    }
  }

</style>
<style lang="scss">
  .introduce-text-box {
    padding: 4px;
    > div {
      font-size: 12px;
      font-weight: 400;
      color: #aaaaaa;
      line-height: 24px;
      padding-left: 16px;
      position: relative;
      &:before {
        position: absolute;
        left: 0;
        top: 8px;
        width: 8px;
        height: 8px;
        border-radius: 4px;
        content: "";
      }
      &:nth-child(1):before {
        background-color: #67C23A;
      }
      &:nth-child(2):before {
        background-color: #606266;
      }
    }
  }
</style>
